<!DOCTYPE html>
<html>
<head>
    <title>Helium Energy Levels</title>
</head>
<body>

<canvas id="heliumEnergyLevelsCanvas" width="550" height="450" style="border:1px solid #000;"></canvas>

<script>
    const canvas = document.getElementById('heliumEnergyLevelsCanvas');
    const ctx = canvas.getContext('2d');

    // Clear canvas
    ctx.fillStyle = "white";
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    
    // Style settings
    ctx.strokeStyle = "black";
    ctx.fillStyle = "black";
    ctx.lineWidth = 1.5;

    // --- Draw Frame ---
    ctx.strokeRect(40, 40, 470, 360);

    // --- Draw Main Labels ---
    ctx.font = "bold 18px sans-serif";
    ctx.textAlign = "center";
    ctx.textBaseline = "middle";
    ctx.fillText("Singlet", 160, 70);
    ctx.fillText("Triplet", 370, 70);
    ctx.font = "16px sans-serif";
    ctx.fillText("Fig. 1.24", 275, 425);

    // --- Energy Level Coordinates & Constants ---
    const lineLen = 90;
    const xSinglet = 160;
    const xTriplet = 370;

    const xSingletStart = xSinglet - lineLen / 2;
    const xSingletEnd = xSinglet + lineLen / 2;
    const xTripletStart = xTriplet - lineLen / 2;
    const xTripletEnd = xTriplet + lineLen / 2;

    const yA = 370;
    const yB = 250;
    const yC = 200;
    const yD = 280;
    const yE = 180;

    // --- Draw Energy Levels and their labels ---
    ctx.lineWidth = 2;
    ctx.textAlign = "start";

    // --- Draw Level A ---
    ctx.beginPath();
    ctx.moveTo(xSingletStart, yA);
    ctx.lineTo(xSingletEnd, yA);
    ctx.stroke();
    ctx.font = "bold 18px sans-serif";
    ctx.fillText("A", xSingletStart - 40, yA);
    // Term symbol: 1¹S₀
    const xTermA = xSingletEnd + 15;
    ctx.font = "18px sans-serif";
    ctx.fillText("1", xTermA, yA);
    ctx.fillText("S", xTermA + 20, yA);
    ctx.font = "12px sans-serif";
    ctx.fillText("1", xTermA + 10, yA - 8); // superscript
    ctx.fillText("0", xTermA + 34, yA + 8); // subscript

    // --- Draw Level B ---
    ctx.beginPath();
    ctx.moveTo(xSingletStart, yB);
    ctx.lineTo(xSingletEnd, yB);
    ctx.stroke();
    ctx.font = "bold 18px sans-serif";
    ctx.fillText("B", xSingletStart - 40, yB);
    // Term symbol: 2¹S₀
    const xTermB = xSingletEnd + 15;
    ctx.font = "18px sans-serif";
    ctx.fillText("2", xTermB, yB);
    ctx.fillText("S", xTermB + 20, yB);
    ctx.font = "12px sans-serif";
    ctx.fillText("1", xTermB + 10, yB - 8); // superscript
    ctx.fillText("0", xTermB + 34, yB + 8); // subscript

    // --- Draw Level C ---
    ctx.beginPath();
    ctx.moveTo(xSingletStart, yC);
    ctx.lineTo(xSingletEnd, yC);
    ctx.stroke();
    ctx.font = "bold 18px sans-serif";
    ctx.fillText("C", xSingletStart - 40, yC);
    // Term symbol: 2¹P₁
    const xTermC = xSingletEnd + 15;
    ctx.font = "18px sans-serif";
    ctx.fillText("2", xTermC, yC);
    ctx.fillText("P", xTermC + 20, yC);
    ctx.font = "12px sans-serif";
    ctx.fillText("1", xTermC + 10, yC - 8); // superscript
    ctx.fillText("1", xTermC + 34, yC + 8); // subscript

    // --- Draw Level D ---
    ctx.beginPath();
    ctx.moveTo(xTripletStart, yD);
    ctx.lineTo(xTripletEnd, yD);
    ctx.stroke();
    ctx.font = "bold 18px sans-serif";
    ctx.fillText("D", xTripletStart - 40, yD);
    // Term symbol: 2³S₁
    const xTermD = xTripletEnd + 15;
    ctx.font = "18px sans-serif";
    ctx.fillText("2", xTermD, yD);
    ctx.fillText("S", xTermD + 20, yD);
    ctx.font = "12px sans-serif";
    ctx.fillText("3", xTermD + 10, yD - 8); // superscript
    ctx.fillText("1", xTermD + 34, yD + 8); // subscript

    // --- Draw Level E ---
    ctx.beginPath();
    ctx.moveTo(xTripletStart, yE);
    ctx.lineTo(xTripletEnd, yE);
    ctx.stroke();
    ctx.font = "bold 18px sans-serif";
    ctx.fillText("E", xTripletStart - 40, yE);
    // Term symbol: 2³P₂,₁,₀
    const xTermE = xTripletEnd + 15;
    ctx.font = "18px sans-serif";
    ctx.fillText("2", xTermE, yE);
    ctx.fillText("P", xTermE + 20, yE);
    ctx.font = "12px sans-serif";
    ctx.fillText("3", xTermE + 10, yE - 8); // superscript
    ctx.fillText("2,1,0", xTermE + 34, yE + 8); // subscript
    
    // --- Draw n labels ---
    ctx.font = "18px sans-serif";
    ctx.fillText("n = 1", 450, 340);
    ctx.fillText("n = 2", 450, 280);

</script>

</body>
</html>